<!--封装公共的分页组件-->
<template>
    <div style="margin-top: 20px">
        <el-pagination
                :background="background"
                :current-page.sync="currentPage"
                :page-size.sync="pageSize"
                :layout="layout"
                :page-sizes="pageSizes"
                :total="total"
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"></el-pagination>
    </div>

</template>

<script>
    export default {
        name: "Pagination",
        props: {
            total: {
                required: true,
                type: Number
            },
            page: {
                type: Number,
                default: 1  //默认第一页
            },
            limit: {
                type: Number,
                default: 10  //默认每页10条
            },
            pageSizes: {
                type: Array,
                default() {
                    return [10, 20, 30, 50]  //默认显示可选的每页多少条数据
                }
            },
            layout: {
                type: String,
                default: 'total, sizes, prev, pager, next, jumper'
            },
            background: {
                type: Boolean,
                default: true
            },
            autoScroll: {
                type: Boolean,
                default: true
            },
            hidden: {
                type: Boolean,
                default: false
            }
        },
        computed: {
            currentPage: {
                get() {
                    return this.page
                },
                set(val) {
                    this.$emit('update:page', val)  //改变的第几页的值赋值给父组件
                }
            },
            pageSize: {
                get() {
                    return this.limit
                },
                set(val) {
                    this.$emit('update:limit', val) //改变的当前页几条数据的值赋值给父组件
                }
            }
        },
        methods: {
            handleSizeChange(val) {
                this.$emit('pagination', { pageIndex: 1, pageSize: val })

            },
            handleCurrentChange(val) {
                this.$emit('pagination', { pageIndex: val, pageSize: this.pageSize })

            }
        }
    }
</script>

<style scoped>

</style>